﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// NewYear2012 的摘要说明
/// </summary>
public class NewYear2012
{
    public static string Conn =  getsql.getstr("activestr"); //"server=.;User ID=sa;Password=wuxinjie;database=TenTianGe;Connection Reset=FALSE";
	public NewYear2012()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}

 

    public static int draw(long useridx, string username)
    {
        if (DateTime.Now.CompareTo(DateTime.Parse("2012-01-28 00:00:15")) >0)
        {
            return -3;
        }
          if (DateTime.Now.CompareTo(DateTime.Parse("2012-01-21 00:00:00")) <0)
        {
            return -4;
        }
        int num = 0;
        try
        {

            SqlParameter[] p =
                    {
          
                         SqlHelper.MakeInParam("@type",SqlDbType.Int,4,1),
                        SqlHelper.MakeInParam("@useridx",SqlDbType.BigInt,15,useridx),
                        SqlHelper.MakeInParam("@username",SqlDbType.VarChar,100,username),
                        SqlHelper.MakeOutParam("@WinNum",SqlDbType.Int,4)
                 
                    };
             SqlHelper.ExecuteNonQuery(Conn, CommandType.StoredProcedure, "[pr_NewYear2012]", p);
             num = int.Parse(p[3].Value.ToString());
        }
        catch
        {
            return -2;
        }
    

         return num;
    }

    public static int GetMoney(long useridx, string username)
    {
        int num = 0;
        //取收取礼物排名
        try
        {

            SqlParameter[] p =
                    {
          
                         SqlHelper.MakeInParam("@type",SqlDbType.Int,4,2),
                        SqlHelper.MakeInParam("@useridx",SqlDbType.BigInt,15,useridx),
                        SqlHelper.MakeInParam("@username",SqlDbType.VarChar,100,username),
                        SqlHelper.MakeOutParam("@WinNum",SqlDbType.Int,4)
                 
                    };
            SqlHelper.ExecuteNonQuery(Conn, CommandType.StoredProcedure, "[pr_NewYear2012]", p);
            num = int.Parse(p[3].Value.ToString());
        }
        catch
        {
            return -2;
        }

        return num;
    }


    public static string  Load(long useridx,string username)
    {
         DataSet ds = null;
         string str = string.Empty;
         string strTemp = string.Empty;
        //取收取礼物排名
        try
        {

            SqlParameter[] p =
                    {
          
                         SqlHelper.MakeInParam("@type",SqlDbType.Int,4,3),
                        SqlHelper.MakeInParam("@useridx",SqlDbType.BigInt,15,useridx),
                        SqlHelper.MakeInParam("@username",SqlDbType.VarChar,100,username),
                        SqlHelper.MakeOutParam("@WinNum",SqlDbType.Int,4)
                 
                    };
            ds = SqlHelper.ExecuteDataset(Conn, CommandType.StoredProcedure, "[pr_NewYear2012]", p);
        }
        catch
        {
            str = "[系统错误，请刷新],[系统错误，请刷新],[系统错误，请刷新],[系统错误，请刷新],[系统错误，请刷新]";
        }
        if (ds != null && ds.Tables.Count >= 4)
        {
            //及时中奖名单
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                strTemp = strTemp +"["+ ds.Tables[0].Rows[i]["nickname"].ToString()+"]" + (ds.Tables[0].Rows[i]["WinMoney"].ToString() != "0" ? "获得金币" + ds.Tables[0].Rows[i]["WinMoney"].ToString() : ("集齐龙珠，获得金币" + ds.Tables[0].Rows[i]["WinBigMoney"].ToString()))+".           ";

            }
            if (strTemp != null && strTemp.Length > 0)
            {
                strTemp = strTemp.Replace(',', ' ');
            }
            str =str+strTemp + ",";
            strTemp=string.Empty;
            strTemp = strTemp + "<li class='mb5 fc01'><span class='nu0 fb'>排名</span><span class='name fb'>用户昵称</span><span class='val fb'>收到龙珠</span></li>";
            //龙珠排行榜
            for (int i = 0; i < ds.Tables[1].Rows.Count; i++)
            {
                strTemp = strTemp + "<li " + (i % 2 == 0 ? "class='mpkey'" : " ") + "><span class='nu1'>" + (i + 1).ToString() + "</span><span class='name'>" + ds.Tables[1].Rows[i]["myname"].ToString() + "</span><span class='val'>" + ds.Tables[1].Rows[i]["num"].ToString() + "</span></li>";
                
            }
            if (strTemp != null && strTemp.Length > 0)
            {
                strTemp = strTemp.Replace(',', ' ');
            }
            str = str + strTemp + ",";
            strTemp = string.Empty;
            //龙珠样式
            for (int i = 0; i < 7; i++)
            {

                strTemp = strTemp + (int.Parse(ds.Tables[2].Rows[0]["num"].ToString()) >= i + 1 ? "<div class='mlz" + (i + 1).ToString() + "'></div>" : "<div class='mlz" + (i + 1).ToString() + "h'></div>");
            }
            str = str + strTemp + ",";
            //龙珠数
            str = str + ds.Tables[2].Rows[0]["num"].ToString() + ",";
            //剩余抽奖次数
            str = str + ds.Tables[3].Rows[0]["num"].ToString() + ",";

        }

        return str;

    }

}
